package com.neardrug.controller;

import com.neardrug.common.Constants;
import com.neardrug.common.Result;
import com.neardrug.controller.dto.FormHTMLUpdateDTO;
import com.neardrug.exception.ServiceException;
import com.neardrug.services.FormService;
import com.neardrug.vo.FormVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

@RestController
@Api(tags = "表格页面")
@RequestMapping("/form")
public class FormController {

    @Resource
    private FormService formService;

    //写在这里不规范 改为写到ApiResultController里面去查询数据
//    @GetMapping("/{id}")
//    @ApiOperation("根据任务id查询出该任务表格页面的所有数据")
//    public Result selectByTaskId(@PathVariable Integer id){
//        if (id == null){
//            throw new ServiceException(Constants.PARAM_ERROR,"参数为空");
//        }
//        FormVO formVO =formService.selectByTaskId(id);
//        return Result.success(formVO);
//    }

    @PostMapping("/updateHTML")
    @ApiOperation("修改某个html表格")
    public Result updateHTML(@RequestBody FormHTMLUpdateDTO formHTMLUpdateDTO){
        if (formHTMLUpdateDTO == null){
            throw new ServiceException(Constants.PARAM_ERROR,"参数为空");
        }
        formService.updateHTML(formHTMLUpdateDTO);
        return Result.success();
    }

    @DeleteMapping("/html/{id}")
    @ApiOperation("根据html表格的id删除这个html表格")
    public Result deleteHtmlById(@PathVariable Integer id){
        if (id==null || id<=0){
            throw new ServiceException(Constants.PARAM_ERROR,"参数不合法");
        }
        formService.deleteHtmlById(id);
        return Result.success();
    }

}
